const type = [];
const funcList = {};
const subject = function () {
  const next = function (name, res) {
    let status = false;
    for (let i = 0; i < type.length; i++) {
      if (type[i].name === name) {
        type[i].fn(res);
        status = true;
        return false;
      } else {
        status = false;
      }
    }
    if (!status) {
      const params = {
        name: name,
        fn:  funcList[name]
      }
      type.push(params);
      params.fn(res);
    }
  }
  const subscribe = function (name, fn) {
    funcList[name] = fn;
  }
  return {
    next: next,
    subscribe: subscribe
  }
}
